package controller

import (
	"gin-easy/pkg/code"
	"gin-easy/pkg/response"
	"gin-easy/service"
	"github.com/gin-gonic/gin"
	"net/http"
)

type Article struct {
	Title   string `json:"title" binding:"required"`
	Content string `json:"content" binding:"required"`
}

/*
*
新建文章
*/
func ArticleSet(c *gin.Context) {
	//参数校验
	var a Article
	if err := c.ShouldBindJSON(&a); err != nil {
		response.ResponseJson(c, http.StatusInternalServerError, code.ERROR, err.Error())
	}
	//新建文章
	articleService := service.Article{Title: a.Title, Content: a.Content}
	if res := articleService.ArticleAdd(); !res {
		response.ResponseJson(c, http.StatusInternalServerError, code.ERROR, nil)
		return
	}
	response.ResponseJson(c, http.StatusOK, code.SUCCESS, nil)

}
